package com.baizhi.service;

import com.baizhi.annotations.RedisCache;
import com.baizhi.dao.BrandMapper;
import com.baizhi.entity.Brand;
import com.baizhi.entity.BrandExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("brandService")
@Transactional
public class BrandServiceImpl implements BrandService{

    @Resource
    private BrandMapper brandMapper;
    BrandExample brandExample = new BrandExample();

    @Override
    @RedisCache
    public List<Brand> findAll() {
        return brandMapper.selectByExample(brandExample);
    }

    @Override
    @RedisCache
    public Brand findById(String id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Brand brand) {
        brandMapper.updateByPrimaryKeySelective(brand);
    }

    @Override
    public void save(Brand brand) {
        brandMapper.insert(brand);
    }

    @Override
    public void delete(String id) {
        brandMapper.deleteByPrimaryKey(id);
    }
}
